package com.triones.yjj.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.triones.yjj.entity.ActivityPrizeDO;
import com.triones.yjj.entity.bo.WxActivityPrizeListParams;
import com.triones.yjj.entity.vo.WxActivityPrizeVO;
import com.triones.yjj.mapper.ActivityPrizeMapper;
import com.triones.yjj.service.ActivityPrizeService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 活动管理 service 业务实现
 *
 * @Author: triones
 */
@Service
@RequiredArgsConstructor
public class ActivityPrizeServiceImpl implements ActivityPrizeService {

    private final ActivityPrizeMapper activityPrizeMapper;


    @Override
    public List<WxActivityPrizeVO> getWxActivityPrizeList(WxActivityPrizeListParams params) {
        int inviteNum = params.getInviteNum();
        QueryWrapper<ActivityPrizeDO> wrapper = Wrappers.query();
        wrapper.orderByAsc("requirement_invite_number");
        wrapper.eq("user_id",params.getUserId());
        wrapper.eq("activity_id",params.getActivityId());
        List<WxActivityPrizeVO> list = activityPrizeMapper.selectVoList(wrapper,WxActivityPrizeVO.class);
        if(list!=null && list.size()>0){
            int preNum = 0;
            for(WxActivityPrizeVO vo:list){
               int requirementInviteNum = vo.getRequirementInviteNumber();
                if(inviteNum>=requirementInviteNum){
                    vo.setActiveState(1);//已达成
                }else{
                    if(inviteNum>preNum && inviteNum<requirementInviteNum){
                        vo.setActiveState(2);//进行中
                    }else{
                        vo.setActiveState(2);//未达成
                    }
                }
                vo.setInviteNum(inviteNum);
                preNum = requirementInviteNum;
            }
        }
        return list;
    }


}
